package com.example.day3;

/**
 * @author zjianfa
 */
public class PrimeNumbers {

    public static void main(String[] args) {
        int count = 0;
        for (int n = 2; count < 100; n++) {
            if(palindromes(n) == 1 && prime(n) == 1) {
                count++;
                System.out.print(n + " ");
                if (count % 10 == 0) {
                    System.out.println();
                }
            }
        }
    }

    public static int palindromes(int n) {
        int a = 1;
        String s = String.valueOf(n);
        int length = s.length();
        for (int i = 0; i <= length / 2; i++) {
            if (s.charAt(i) != s.charAt(length - 1 - i)) {
                a = 0;
                break;
            }
        }
        return a;
    }

    public static int prime(int n){
        int a = 1;
        for (int i = 2; i < n - 1; i++) {
            if(n % i == 0 ){
                a = 0;
                break;
            }
        }
        return a;
    }
}
